package com.xujiang.mytool.GlideTest;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;

import com.xujiang.common_adapter.core.RecyclerViewHelper;
import com.xujiang.mytool.Base.BaseActivity;
import com.xujiang.mytool.GlideTest.adapter.GlideDemoAdapter;
import com.xujiang.mytool.GlideTest.model.GlideMode;
import com.xujiang.mytool.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author xujiang
 * @version 2017-08-09 14:30
 */
public class GlideDemo extends BaseActivity {

    @BindView(R.id.ek_ca_list_recycler_view)
    RecyclerView ekCaListRecyclerView;

    //private CPProgressHelper mProgressHelper;

    RecyclerViewHelper mRecyclerViewHelper;

    //ProgressDialog mProgressDialog;
    private GlideDemoAdapter adapter;
    List<GlideMode> list = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_glide_demo);
        ButterKnife.bind(this);
        initToolBar();
        //mProgressHelper = CPProgressHelper.with(this);
        //mProgressDialog = ProgressDialog.newBuilder(this).noClose().get();
        adapter = new GlideDemoAdapter(getActivity(), getActivity());
        list.add(new GlideMode(
                "http://c.hiphotos.baidu.com/zhidao/pic/item/0823dd54564e9258c3d23fbd9a82d158cdbf4efa.jpg", "1"));
        list.add(new GlideMode(
                "http://g.hiphotos.baidu.com/zhidao/pic/item/8435e5dde71190ef103f8380ce1b9d16fcfa60ac.jpg", "2"));
        list.add(new GlideMode(
                "http://c.hiphotos.baidu.com/zhidao/pic/item/eaf81a4c510fd9f9dde62291272dd42a2934a450.jpg", "3"));
        adapter.setList(list);

        mRecyclerViewHelper = RecyclerViewHelper
                .newBuilder(getActivity())
                .setRefreshListener(new RecyclerViewHelper.RefreshListener() {
                    @Override
                    public void onRefresh() {
                        setData();
                    }
                })
                .enableHorizontalDividerLineResId(
                        R.color.divider_line)
                .setAdapter(adapter)
                .build();

        setData();

    }

    public void setData() {
        adapter.setList(list);
        adapter.notifyDataSetChanged();
        mRecyclerViewHelper.setSwipeRefreshing(false);  // 隐藏刷新
    }
}
